home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / cvs-1.8 / cvs-1 / cvs-1.8.1 / src / status.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  6.1 KB  |  280 lines

  1. /*
  2.  * Copyright (c) 1992, Brian Berliner and Jeff Polk
  3.  * Copyright (c) 1989-1992, Brian Berliner
  4.  * 
  5.  * You may distribute under the terms of the GNU General Public License as
  6.  * specified in the README file that comes with the CVS 1.4 kit.
  7.  * 
  8.  * Status Information
  9.  */
  10.  
  11. #include "cvs.h"
  12.  
  13. static Dtype status_dirproc PROTO((char *dir, char *repos, char *update_dir));
  14. static int status_fileproc PROTO((struct file_info *finfo));
  15. static int tag_list_proc PROTO((Node * p, void *closure));
  16.  
  17. static int local = 0;
  18. static int long_format = 0;
  19. static RCSNode *xrcsnode;
  20.  
  21. static const char *const status_usage[] =
  22. {
  23.     "Usage: %s %s [-vlR] [files...]\n",
  24.     "\t-v\tVerbose format; includes tag information for the file\n",
  25.     "\t-l\tProcess this directory only (not recursive).\n",
  26.     "\t-R\tProcess directories recursively.\n",
  27.     NULL
  28. };
  29.  
  30. int
  31. status (argc, argv)
  32.     int argc;
  33.     char **argv;
  34. {
  35.     int c;
  36.     int err = 0;
  37.  
  38.     if (argc == -1)
  39.     usage (status_usage);
  40.  
  41.     optind = 1;
  42.     while ((c = getopt (argc, argv, "vlR")) != -1)
  43.     {
  44.     switch (c)
  45.     {
  46.         case 'v':
  47.         long_format = 1;
  48.         break;
  49.         case 'l':
  50.         local = 1;
  51.         break;
  52.         case 'R':
  53.         local = 0;
  54.         break;
  55.         case '?':
  56.         default:
  57.         usage (status_usage);
  58.         break;
  59.     }
  60.     }
  61.     argc -= optind;
  62.     argv += optind;
  63.  
  64.     wrap_setup ();
  65.  
  66. #ifdef CLIENT_SUPPORT
  67.     if (client_active) {
  68.       start_server ();
  69.  
  70.       ign_setup ();
  71.  
  72.       if (long_format)
  73.     send_arg("-v");
  74.       if (local)
  75.     send_arg("-l");
  76.  
  77.       send_file_names (argc, argv, SEND_EXPAND_WILD);
  78.       /* XXX This should only need to send file info; the file
  79.      contents themselves will not be examined.  */
  80.       send_files (argc, argv, local, 0);
  81.  
  82.       send_to_server ("status\012", 0);
  83.       err = get_responses_and_close ();
  84.  
  85.       return err;
  86.     }
  87. #endif
  88.  
  89.     /* start the recursion processor */
  90.     err = start_recursion (status_fileproc, (FILESDONEPROC) NULL, status_dirproc,
  91.                (DIRLEAVEPROC) NULL, argc, argv, local,
  92.                W_LOCAL, 0, 1, (char *) NULL, 1, 0);
  93.  
  94.     return (err);
  95. }
  96.  
  97. /*
  98.  * display the status of a file
  99.  */
  100. /* ARGSUSED */
  101. static int
  102. status_fileproc (finfo)
  103.     struct file_info *finfo;
  104. {
  105.     Ctype status;
  106.     char *sstat;
  107.     Vers_TS *vers;
  108.  
  109.     status = Classify_File (finfo->file, (char *) NULL, (char *) NULL, (char *) NULL,
  110.                 1, 0, finfo->repository, finfo->entries, finfo->rcs, &vers,
  111.                 finfo->update_dir, 0);
  112.     switch (status)
  113.     {
  114.     case T_UNKNOWN:
  115.         sstat = "Unknown";
  116.         break;
  117.     case T_CHECKOUT:
  118.         sstat = "Needs Checkout";
  119.         break;
  120. #ifdef SERVER_SUPPORT
  121.     case T_PATCH:
  122.         sstat = "Needs Patch";
  123.         break;
  124. #endif
  125.     case T_CONFLICT:
  126.         sstat = "Unresolved Conflict";
  127.         break;
  128.     case T_ADDED:
  129.         sstat = "Locally Added";
  130.         break;
  131.     case T_REMOVED:
  132.         sstat = "Locally Removed";
  133.         break;
  134.     case T_MODIFIED:
  135.         if (vers->ts_conflict)
  136.         sstat = "Unresolved Conflict";
  137.         else
  138.         sstat = "Locally Modified";
  139.         break;
  140.     case T_REMOVE_ENTRY:
  141.         sstat = "Entry Invalid";
  142.         break;
  143.     case T_UPTODATE:
  144.         sstat = "Up-to-date";
  145.         break;
  146.     case T_NEEDS_MERGE:
  147.         sstat = "Needs Merge";
  148.         break;
  149.     default:
  150.         sstat = "Classify Error";
  151.         break;
  152.     }
  153.  
  154.     (void) printf ("===================================================================\n");
  155.     if (vers->ts_user == NULL)
  156.     (void) printf ("File: no file %s\t\tStatus: %s\n\n", finfo->file, sstat);
  157.     else
  158.     (void) printf ("File: %-17s\tStatus: %s\n\n", finfo->file, sstat);
  159.  
  160.     if (vers->vn_user == NULL)
  161.     (void) printf ("   Working revision:\tNo entry for %s\n", finfo->file);
  162.     else if (vers->vn_user[0] == '0' && vers->vn_user[1] == '\0')
  163.     (void) printf ("   Working revision:\tNew file!\n");
  164. #ifdef SERVER_SUPPORT
  165.     else if (server_active)
  166.     (void) printf ("   Working revision:\t%s\n", vers->vn_user);
  167. #endif
  168.     else
  169.     (void) printf ("   Working revision:\t%s\t%s\n", vers->vn_user,
  170.                vers->ts_rcs);
  171.  
  172.     if (vers->vn_rcs == NULL)
  173.     (void) printf ("   Repository revision:\tNo revision control file\n");
  174.     else
  175.     (void) printf ("   Repository revision:\t%s\t%s\n", vers->vn_rcs,
  176.                vers->srcfile->path);
  177.  
  178.     if (vers->entdata)
  179.     {
  180.     Entnode *edata;
  181.  
  182.     edata = vers->entdata;
  183.     if (edata->tag)
  184.     {
  185.         if (vers->vn_rcs == NULL)
  186.         (void) printf (
  187.              "   Sticky Tag:\t\t%s - MISSING from RCS file!\n",
  188.              edata->tag);
  189.         else
  190.         {
  191.         if (isdigit (edata->tag[0]))
  192.             (void) printf ("   Sticky Tag:\t\t%s\n", edata->tag);
  193.         else
  194.         {
  195.             char *branch = NULL;
  196.     
  197.             if (RCS_isbranch (finfo->rcs, edata->tag))
  198.             branch = RCS_whatbranch(finfo->rcs, edata->tag);
  199.  
  200.             (void) printf ("   Sticky Tag:\t\t%s (%s: %s)\n",
  201.                    edata->tag,
  202.                    branch ? "branch" : "revision",
  203.                    branch ? branch : vers->vn_rcs);
  204.  
  205.             if (branch)
  206.             free (branch);
  207.         }
  208.         }
  209.     }
  210.     else if (!really_quiet)
  211.         (void) printf ("   Sticky Tag:\t\t(none)\n");
  212.  
  213.     if (edata->date)
  214.         (void) printf ("   Sticky Date:\t\t%s\n", edata->date);
  215.     else if (!really_quiet)
  216.         (void) printf ("   Sticky Date:\t\t(none)\n");
  217.  
  218.     if (edata->options && edata->options[0])
  219.         (void) printf ("   Sticky Options:\t%s\n", edata->options);
  220.     else if (!really_quiet)
  221.         (void) printf ("   Sticky Options:\t(none)\n");
  222.  
  223.     if (long_format && vers->srcfile)
  224.     {
  225.         List *symbols = RCS_symbols(vers->srcfile);
  226.  
  227.         (void) printf ("\n   Existing Tags:\n");
  228.         if (symbols)
  229.         {
  230.         xrcsnode = finfo->rcs;
  231.         (void) walklist (symbols, tag_list_proc, NULL);
  232.         }
  233.         else
  234.         (void) printf ("\tNo Tags Exist\n");
  235.     }
  236.     }
  237.  
  238.     (void) printf ("\n");
  239.     freevers_ts (&vers);
  240.     return (0);
  241. }
  242.  
  243. /*
  244.  * Print a warm fuzzy message
  245.  */
  246. /* ARGSUSED */
  247. static Dtype
  248. status_dirproc (dir, repos, update_dir)
  249.     char *dir;
  250.     char *repos;
  251.     char *update_dir;
  252. {
  253.     if (!quiet)
  254.     error (0, 0, "Examining %s", update_dir);
  255.     return (R_PROCESS);
  256. }
  257.  
  258. /*
  259.  * Print out a tag and its type
  260.  */
  261. static int
  262. tag_list_proc (p, closure)
  263.     Node *p;
  264.     void *closure;
  265. {
  266.     char *branch = NULL;
  267.  
  268.     if (RCS_isbranch (xrcsnode, p->key))
  269.     branch = RCS_whatbranch(xrcsnode, p->key) ;
  270.  
  271.     (void) printf ("\t%-25.25s\t(%s: %s)\n", p->key,
  272.            branch ? "branch" : "revision",
  273.            branch ? branch : p->data);
  274.  
  275.     if (branch)
  276.     free (branch);
  277.  
  278.     return (0);
  279. }
  280.